package com.dongdong.zhuangji.config;
import com.dongdong.zhuangji.utils.StringToDateConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.format.FormatterRegistry;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import org.springframework.web.util.pattern.PathPatternParser;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Bean
    // 重命名 Bean
    public StringToDateConverter customStringToDateConverter() {
        return new StringToDateConverter();
    }

    @Override
    public void addFormatters(FormatterRegistry registry) {
        // 使用重命名后的 Bean
        registry.addConverter(customStringToDateConverter());
    }
    /*@GetMapping("/**")
    public String index() {
        return "index";
    }*/



    @Override
    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/**")
                .addResourceLocations("classpath:/static/");
    }

    /*@Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/{path:^(?!.*\\.js|\\.css|\\.html|\\.png|\\.jpg|\\.svg|\\.ico).*$}")
                .setViewName("forward:/index.html");
        registry.addViewController("/")
                .setViewName("forward:/index.html");
    }*/

    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        configurer.setPatternParser(new PathPatternParser());
    }
}